<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="宠物" prop="petId">
        <el-select v-model="queryParams.petId" placeholder="请选择宠物">
          <el-option v-for="item in petList" :key="item.petId" :label="item.name" :value="item.petId" />
        </el-select>
      </el-form-item>
      <el-form-item label="医生" prop="doctorId">
        <el-select v-model="queryParams.doctorId" placeholder="请选择医生">
          <el-option v-for="item in doctorList" :key="item.userId" :label="item.userName" :value="item.userId" />
        </el-select>
      </el-form-item>
      <el-form-item label="诊疗日期" prop="recordDate">
        <el-date-picker clearable v-model="queryParams.recordDate" type="date" value-format="yyyy-MM-dd"
          placeholder="请选择诊疗日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>


    <el-table v-loading="loading" :data="recordList">
      <el-table-column label="诊疗编号" align="center" prop="recordId" />
      <el-table-column label="宠物ID" align="center" prop="petId" />
      <el-table-column label="关联的医生ID" align="center" prop="doctorId" />
      <el-table-column label="诊断结果" align="center" prop="diagnosis" />
      <el-table-column label="治疗方案" align="center" prop="treatment" />
      <el-table-column label="诊疗日期" align="center" prop="recordDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.recordDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>

    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />


  </div>
</template>

<script>
import { listRecord } from "@/api/pet/record";
import { listPet, getPet, delPet, addPet, updatePet } from "@/api/pet/pet";
import { listUser, getUser, delUser, addUser, updateUser, resetUserPwd, changeUserStatus, deptTreeSelect } from "@/api/system/user";
import Cookies from "js-cookie";

export default {
  name: "RecordItem",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 诊疗记录表格数据
      recordList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        petId: null,
        doctorId: null,
        diagnosis: null,
        treatment: null,
        recordDate: null
      },
      // 宠物列表
      petList: [],
      // 医生列表
      doctorList: [],
      queryParamsPet: {
        pageNum: 1,
        pageSize: 10,
        ownerId: null
      },
      queryParamsDoctor: {
        pageNum: 1,
        pageSize: 20,
        deptId: undefined
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询诊疗记录列表 */
    getList() {
      this.loading = true;
      listRecord(this.queryParams).then(response => {
        this.recordList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
      // 获取宠物列表
      this.queryParamsPet.ownerId = Cookies.get("petUserId");
      listPet(this.queryParamsPet).then(response => {
        this.petList = response.rows;
      });
      // 获取医生列表
      this.queryParamsDoctor.deptId = 201;
      listUser(this.queryParamsDoctor).then(response => {
        this.doctorList = response.rows;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },

  }
};
</script>